using Circus.CodeEditor;
using System;
using System.Collections;
using System.Collections.Generic;
using System.Drawing;
using System.Runtime.CompilerServices;
using System.Windows.Forms;
namespace Circus.CodeEditor.TextSource
{
	public class BookMarks : SortList<IBookMark>,IList<IBookMark>, ICollection<IBookMark>, IEnumerable<IBookMark>, IEnumerable
	{
		private class BookMarkComparer : IComparer<IBookMark>
		{
			public int Compare(IBookMark x, IBookMark y)
			{
				int num = x.Line - y.Line;
				if (num == 0)
				{
					num = x.Pos - y.Pos;
				}
				if (num == 0)
				{
					num = x.Index - y.Index;
				}
				return num;
			}
		}
		private class LineComparer : IComparer<IBookMark>
		{
			public int Compare(IBookMark x, IBookMark y)
			{
				return x.Line - y.Line;
			}
		}
		private class PointComparer : IComparer<IBookMark>
		{
			public int Compare(IBookMark x, IBookMark y)
			{
				int num = x.Line - y.Line;
				if (num == 0)
				{
					num = x.Pos - y.Pos;
				}
				return num;
			}
		}
		private class RangeComparer : IComparer
		{
			public int Compare(object x, object y)
			{
				IBookMark bookMark = (IBookMark)x;
				Point startPoint = ((Range)y).StartPoint;
				Point endPoint = ((Range)y).EndPoint;
				int result;
				if (bookMark.Line < startPoint.Y || (bookMark.Line == startPoint.Y && bookMark.Pos < startPoint.X))
				{
					result = -1;
				}
				else
				{
					if (bookMark.Line > endPoint.Y || (bookMark.Line == endPoint.Y && bookMark.Pos >= endPoint.X))
					{
						result = 1;
					}
					else
					{
						result = 0;
					}
				}
				return result;
			}
		}
		protected TextSource owner;
		private bool shared;
		protected IComparer<IBookMark> lineComparer;
		protected IComparer<IBookMark> pointComparer;
		protected IComparer<IBookMark> bookMarkComparer;
		protected IComparer rangeComparer;
	    public  event BookmarkClickEvent Click;

	    public  event BookmarkClickEvent DoubleClick;

	    public  event TooltipEvent ShowToolTip;
		public bool Shared
		{
			get
			{
				return this.shared;
			}
			set
			{
				if (this.shared != value)
				{
					this.OnSharedChaging();
					this.shared = value;
					this.OnSharedChagned();
				}
			}
		}
		private void GotoBookMarkIndex(bool direction)
		{
			this.GotoBookMarkIndex(direction, -1);
		}
		private void GotoBookMarkIndex(bool direction, int group)
		{
			int num = -1;
			if (direction)
			{
				for (int i = 0; i < base.Count; i++)
				{
					IBookMark bookMark = base[i];
					if (bookMark.Index == int.MaxValue && bookMark.Line > this.owner.Position.Y && (bookMark.Group == group || group == -1))
					{
						num = i;
						break;
					}
				}
				if (num == -1)
				{
					for (int i = 0; i < base.Count; i++)
					{
						if (base[i].Index == int.MaxValue && (base[i].Group == group || group == -1))
						{
							num = i;
							break;
						}
					}
				}
			}
			else
			{
				for (int i = base.Count - 1; i >= 0; i--)
				{
					IBookMark bookMark = base[i];
					if (bookMark.Index == int.MaxValue && bookMark.Line < this.owner.Position.Y && (bookMark.Group == group || group == -1))
					{
						num = i;
						break;
					}
				}
				if (num == -1)
				{
					for (int i = base.Count - 1; i >= 0; i--)
					{
						if (base[i].Index == int.MaxValue && (base[i].Group == group || group == -1))
						{
							num = i;
							break;
						}
					}
				}
			}
			if (num >= 0 && num < base.Count)
			{
				IBookMark bookMark = base[num];
				this.owner.BeginUpdate(UpdateReason.Navigate);
				try
				{
					this.owner.State |= (NotifyState.GotoBookMark | NotifyState.CenterLine);
					this.owner.MoveTo(bookMark.Pos, bookMark.Line);
				}
				finally
				{
					this.owner.EndUpdate();
				}
			}
		}
		private void SetBookMark(int line, int pos, int bookMark)
		{
			this.SetBookMark(line, pos, bookMark, -1);
		}
		protected virtual void OnSharedChagned()
		{
		}
		protected virtual void OnSharedChaging()
		{
			this.Clear();
		}
		public virtual void SetBookMark(Point position, int group, int bookMark, int imageIndex, string name, string description, string url, object tag)
		{
			if (this.shared)
			{
				BookMarkManager.SharedBookMarks.SetBookMark(position, group, bookMark, imageIndex, name, description, url, tag, this.owner.FileName);
			}
			else
			{
				this.owner.BeginUpdate(UpdateReason.Other);
				try
				{
					if (bookMark != int.MaxValue)
					{
						this.ClearBookMark(bookMark);
					}
					this.InternalSet(new BookMark(position.Y, position.X, group, bookMark, imageIndex, name, description, url, string.Empty, tag));
					this.owner.LinesChanged(position.Y, position.Y);
					this.owner.State |= NotifyState.BookMarkChanged;
				}
				finally
				{
					this.owner.EndUpdate();
				}
			}
		}
		public virtual void SetBookMark(int line, int group, int bookMark, int imageIndex)
		{
			this.SetBookMark(new Point(0, line), group, bookMark, imageIndex, string.Empty, string.Empty, string.Empty, null);
		}
		public virtual void SetBookMark(Point position, int group, int bookMark, int imageIndex)
		{
			this.SetBookMark(position, group, bookMark, imageIndex, string.Empty, string.Empty, string.Empty, null);
		}
		public virtual void SetBookMark(Point position, int group, int bookMark, int imageIndex, string name, string description, string url)
		{
			this.SetBookMark(position, group, bookMark, imageIndex, name, description, url, null);
		}
		protected virtual IBookMark NewBookMark(int line, int pos, int index)
		{
			return new BookMark(line, pos, index);
		}
		protected virtual bool UpdatePosition(int x, int y, int deltaX, int deltaY, IBookMark bookmark)
		{
			Point point = new Point(bookmark.Pos, bookmark.Line);
			bool result;
			if (SortList<IBookMark>.UpdatePos(x, y, deltaX, deltaY, ref point, point.X != 0))
			{
				bookmark.Position = new Point((bookmark.Index != int.MaxValue) ? point.X : bookmark.Pos, point.Y);
				result = true;
			}
			else
			{
				result = false;
			}
			return result;
		}
		protected virtual bool PositionChanged(int x, int y, int deltaX, int deltaY, IComparer<IBookMark> lineComparer, IComparer<IBookMark> sortComparer)
		{
			bool result;
			if (this.shared)
			{
				result = BookMarkManager.SharedBookMarks.PositionChanged(x, y, deltaX, deltaY, this.owner.FileName);
			}
			else
			{
				int num = 0;
				if (lineComparer != null)
				{
					base.FindFirst(new BookMark(y, 0, 0), out num, lineComparer);
				}
				if (num >= 0)
				{
					bool flag = false;
					for (int i = num; i < base.Count; i++)
					{
						if (this.UpdatePosition(x, y, deltaX, deltaY, base[i]))
						{
							flag = true;
						}
					}
					if (flag)
					{
						if (sortComparer != null)
						{
							base.Sort(sortComparer);
						}
						result = true;
						return result;
					}
				}
				result = false;
			}
			return result;
		}
		protected virtual bool ShouldDelete(IBookMark bm, Rectangle rect)
		{
			bool result;
			if (bm.Index == int.MaxValue)
			{
				result = (SortList<IBookMark>.InsideRange(new Point(0, bm.Line), rect) && (rect.Width == int.MaxValue || SortList<IBookMark>.InsideRange(new Point(int.MaxValue, bm.Line), rect)));
			}
			else
			{
				result = SortList<IBookMark>.InsideRange(new Point(bm.Pos, bm.Line), rect);
			}
			return result;
		}
		protected int InternalGet(int line)
		{
			int index;
			int result;
			if (base.FindFirst(new BookMark(line), out index, this.lineComparer))
			{
				result = base[index].Index;
			}
			else
			{
				result = -1;
			}
			return result;
		}
		protected int InternalGet(int line, int group)
		{
			IBookMark bookMark = new BookMark(line);
			int num;
			int result;
			if (base.FindFirst(bookMark, out num, this.lineComparer))
			{
				for (int i = num; i < base.Count; i++)
				{
					if (this.lineComparer.Compare(base[i], bookMark) != 0)
					{
						break;
					}
					if (base[i].Group == group || group == -1)
					{
						result = base[i].Index;
						return result;
					}
				}
			}
			result = -1;
			return result;
		}
		protected int InternalGet(Point startPoint, Point endPoint, IComparer comparer)
		{
			Range obj = new Range(startPoint, endPoint);
			int index;
			int result;
			if (base.FindFirst(obj, out index, comparer))
			{
				result = base[index].Index;
			}
			else
			{
				result = -1;
			}
			return result;
		}
		protected int InternalGet(Point startPoint, Point endPoint, int group)
		{
			Range range = new Range(startPoint, endPoint);
			int num;
			int result;
			if (base.FindFirst(range, out num, this.rangeComparer))
			{
				for (int i = num; i < base.Count; i++)
				{
					if (this.rangeComparer.Compare(base[i], range) != 0)
					{
						break;
					}
					if (base[i].Group == group || group == -1)
					{
						result = base[i].Index;
						return result;
					}
				}
			}
			result = -1;
			return result;
		}
		protected int InternalGet(Point startPoint, Point endPoint, IList<IBookMark> list, IComparer comparer)
		{
			list.Clear();
			Range range = new Range(startPoint, endPoint);
			int num;
			if (base.FindFirst(range, out num, comparer))
			{
				for (int i = num; i < base.Count; i++)
				{
					if (comparer.Compare(base[i], range) != 0)
					{
						break;
					}
					list.Add(base[i]);
				}
			}
			return list.Count;
		}
		protected int InternalGet(Point startPoint, Point endPoint, int group, IList<IBookMark> list)
		{
			list.Clear();
			Range range = new Range(startPoint, endPoint);
			int num;
			if (base.FindFirst(range, out num, this.rangeComparer))
			{
				for (int i = num; i < base.Count; i++)
				{
					if (this.rangeComparer.Compare(base[i], range) != 0)
					{
						break;
					}
					if (base[i].Group == group || group == -1)
					{
						list.Add(base[i]);
					}
				}
			}
			return list.Count;
		}
		protected void InternalSet(IBookMark bookMark)
		{
			int index;
			if (base.FindFirst(bookMark, out index, this.pointComparer))
			{
				base.RemoveAt(index);
			}
			base.Insert(index, bookMark);
		}
		protected void InternalSet(int line, int index)
		{
			int index2;
			if (base.FindFirst(new BookMark(line), out index2, this.lineComparer))
			{
				base.RemoveAt(index2);
			}
			base.Insert(index2, this.NewBookMark(line, 0, index));
		}
		protected void InternalSet(int line, int pos, int index)
		{
			int index2;
			if (base.FindFirst(new BookMark(line, pos, -1), out index2, this.pointComparer))
			{
				base.RemoveAt(index2);
			}
			base.Insert(index2, this.NewBookMark(line, pos, index));
		}
		protected void InternalClear(int index)
		{
			int num = this.FindByIndex(index);
			if (num >= 0)
			{
				base.RemoveAt(num);
			}
		}
		public virtual int InternalFind(int bookMark, int line)
		{
			int num;
			if (bookMark == int.MaxValue)
			{
				num = this.FindByLine(line);
				while (num >= 0 && num < base.Count && base[num].Line == line)
				{
					if (base[num].Index == bookMark)
					{
						break;
					}
					num++;
				}
			}
			else
			{
				num = this.FindByIndex(bookMark);
			}
			int result;
			if (num >= 0 && num < base.Count && base[num].Line == line)
			{
				result = num;
			}
			else
			{
				result = -1;
			}
			return result;
		}
		public virtual int InternalFind(int bookMark, int line, int group)
		{
			int num;
			if (bookMark == int.MaxValue)
			{
				num = this.FindByLine(line);
				while (num >= 0 && num < base.Count)
				{
					if (base[num].Line != line)
					{
						num = -1;
						break;
					}
					if (base[num].Index == bookMark && (base[num].Group == group || group == -1))
					{
						break;
					}
					num++;
				}
			}
			else
			{
				num = this.FindByIndex(bookMark);
			}
			int result;
			if (num >= 0 && num < base.Count && base[num].Line == line && (base[num].Group == group || group == -1))
			{
				result = num;
			}
			else
			{
				result = -1;
			}
			return result;
		}
		protected void InternalClearLine(int line)
		{
			int num = 0;
			if (base.FindLast(new BookMark(line), out num, this.lineComparer))
			{
				for (int i = num; i >= 0; i--)
				{
					if (base[num].Line != line)
					{
						break;
					}
					base.RemoveAt(i);
				}
			}
		}
		protected int FindByLine(int line)
		{
			int num;
			int result;
			if (base.FindFirst(new BookMark(line), out num, this.lineComparer))
			{
				result = num;
			}
			else
			{
				result = -1;
			}
			return result;
		}
		protected int FindByIndex(int index)
		{
			int result;
			for (int i = 0; i < base.Count; i++)
			{
				if (base[i].Index == index)
				{
					result = i;
					return result;
				}
			}
			result = -1;
			return result;
		}
		public BookMarks()
		{
			this.lineComparer = new BookMarks.LineComparer();
			this.pointComparer = new BookMarks.PointComparer();
			this.bookMarkComparer = new BookMarks.BookMarkComparer();
			this.rangeComparer = new BookMarks.RangeComparer();
		}
		public BookMarks(TextSource owner) : this()
		{
			this.owner = owner;
		}
		public virtual void Assign(BookMarks source)
		{
			this.owner.BeginUpdate(UpdateReason.Other);
			try
			{
				this.Clear();
				foreach (IBookMark current in source)
				{
					base.Add(this.NewBookMark(current.Line, current.Pos, current.Index));
				}
				this.owner.LinesChanged(0, int.MaxValue);
				this.owner.State |= NotifyState.BookMarkChanged;
			}
			finally
			{
				this.owner.EndUpdate();
			}
		}
		public virtual int GetBookMark(int line)
		{
			return this.GetBookMark(line, -1);
		}
		public virtual int GetBookMark(Point startPoint, Point endPoint)
		{
			return this.GetBookMark(startPoint, endPoint, -1);
		}
		public virtual int GetBookMarks(Point startPoint, Point endPoint, IList<IBookMark> list)
		{
			return this.GetBookMarks(startPoint, endPoint, -1, list);
		}
		public virtual int GetBookMarks(IList<IBookMark> list)
		{
			return this.GetBookMarks(-1, list);
		}
		public virtual int GetBookMark(int line, int group)
		{
			return this.shared ? BookMarkManager.SharedBookMarks.GetBookMark(line, group, this.owner.FileName) : this.InternalGet(line, group);
		}
		public virtual int GetBookMark(Point startPoint, Point endPoint, int group)
		{
			return this.shared ? BookMarkManager.SharedBookMarks.GetBookMark(startPoint, endPoint, group, this.owner.FileName) : this.InternalGet(startPoint, endPoint, group);
		}
		public virtual int GetBookMarks(Point startPoint, Point endPoint, int group, IList<IBookMark> list)
		{
			return this.shared ? BookMarkManager.SharedBookMarks.GetBookMarks(startPoint, endPoint, group, this.owner.FileName, list) : this.InternalGet(startPoint, endPoint, group, list);
		}
		public virtual int GetBookMarks(int group, IList<IBookMark> list)
		{
			int result;
			if (this.shared)
			{
				result = BookMarkManager.SharedBookMarks.GetBookMarks(group, this.owner.FileName, list);
			}
			else
			{
				foreach (IBookMark current in this)
				{
					if (current.Group == group || group == -1)
					{
						list.Add(current);
					}
				}
				result = list.Count;
			}
			return result;
		}
		public virtual IBookMark FindBookMark(int bookMark)
		{
			IBookMark result;
			if (this.shared)
			{
				result = BookMarkManager.SharedBookMarks.FindBookMark(bookMark, this.owner.FileName);
			}
			else
			{
				int num = this.FindByIndex(bookMark);
				if (num >= 0)
				{
					result = base[num];
				}
				else
				{
					result = null;
				}
			}
			return result;
		}
		public virtual IBookMark FindBookMark(int bookMark, int line)
		{
			return this.FindBookMark(line, -1, bookMark);
		}
		public virtual IBookMark FindBookMark(int group, int bookMark, int line)
		{
			IBookMark result;
			if (this.shared)
			{
				result = BookMarkManager.SharedBookMarks.FindBookMark(line, group, bookMark, this.owner.FileName);
			}
			else
			{
				int num = this.InternalFind(bookMark, line, group);
				result = ((num >= 0) ? base[num] : null);
			}
			return result;
		}
		public virtual IBookMark FindBookMark(string name)
		{
			IBookMark result;
			if (this.shared)
			{
				result = null;
			}
			else
			{
				foreach (IBookMark current in this)
				{
					if (current.Name == name)
					{
						result = current;
						return result;
					}
				}
				result = null;
			}
			return result;
		}
		public virtual void SetBookMark(int line, int bookMark)
		{
			this.SetBookMark(line, 0, bookMark, -1);
		}
		public virtual void SetBookMark(Point position, int bookMark)
		{
			this.SetBookMark(position, 0, bookMark, -1);
		}
		public virtual void SetBookMark(IBookMark bookMark)
		{
			if (this.shared)
			{
				BookMarkManager.SharedBookMarks.SetBookMark(bookMark.Position, bookMark.Group, bookMark.Index, bookMark.ImageIndex, bookMark.Name, bookMark.Description, bookMark.Url, bookMark.Tag, bookMark.FileName);
			}
			else
			{
				this.SetBookMark(bookMark.Position, bookMark.Index, bookMark.Name, bookMark.Description, bookMark.Url);
			}
		}
		public virtual void SetBookMark(Point position, int bookMark, string name, string description, string url)
		{
			this.SetBookMark(position, 0, bookMark, -1, name, description, url);
		}
		public virtual void SetBookMark(Point position, int bookMark, string name, string description, string url, int imageIndex, string fileName, object tag, bool clear)
		{
			if (this.shared)
			{
				BookMarkManager.SharedBookMarks.SetBookMark(position, 0, bookMark, imageIndex, name, description, url, tag, fileName);
			}
			else
			{
				this.owner.BeginUpdate(UpdateReason.Other);
				try
				{
					if (clear && bookMark != int.MaxValue)
					{
						this.ClearBookMark(bookMark);
					}
					this.InternalSet(new BookMark(position.Y, position.X, bookMark, name, description, url, imageIndex, fileName, tag));
					this.owner.LinesChanged(position.Y, position.Y);
					this.owner.State |= NotifyState.BookMarkChanged;
				}
				finally
				{
					this.owner.EndUpdate();
				}
			}
		}
		public virtual bool FindBookMark(int bookMark, out Point position)
		{
			bool result;
			if (this.shared)
			{
				position = new Point(0, 0);
				result = false;
			}
			else
			{
				int num = this.FindByIndex(bookMark);
				if (num >= 0)
				{
					IBookMark bookMark2 = base[num];
					position = new Point(bookMark2.Pos, bookMark2.Line);
					result = true;
				}
				else
				{
					position = new Point(0, 0);
					result = false;
				}
			}
			return result;
		}
		public virtual void ToggleBookMark(int line, int bookMark)
		{
			this.ToggleBookMark(line, 0, bookMark, -1);
		}
		public virtual void ToggleBookMark(Point position, int bookMark)
		{
			this.ToggleBookMark(position, 0, bookMark, -1);
		}
		public virtual void ToggleBookMark(IBookMark bookMark)
		{
			if (this.shared)
			{
				BookMarkManager.SharedBookMarks.ToggleBookMark(bookMark.Position, bookMark.Group, bookMark.Index, bookMark.ImageIndex, bookMark.Name, bookMark.Description, bookMark.Url, bookMark.Tag, bookMark.FileName);
			}
			else
			{
				this.ToggleBookMark(bookMark.Position, bookMark.Index, bookMark.Name, bookMark.Description, bookMark.Url, bookMark.ImageIndex, bookMark.FileName, bookMark.Tag);
			}
		}
		public virtual void ToggleBookMark(Point position, int bookMark, string name, string description, string url)
		{
			this.ToggleBookMark(position, 0, bookMark, -1, name, description, url);
		}
		public virtual void ToggleBookMark(Point position, int bookMark, string name, string description, string url, int imageIndex, string fileName, object tag)
		{
			this.ToggleBookMark(position, 0, bookMark, imageIndex, name, description, url, tag);
		}
		public virtual void SetForcedMarker(Point position, int bookMark, string name, string description, string url, int imageIndex, string fileName, object tag)
		{
			this.SetBookMark(position, bookMark, name, description, url, imageIndex, fileName, tag, false);
		}
		public virtual void ToggleBookMark(int bookMark)
		{
			this.ToggleBookMark(this.owner.Position, bookMark);
		}
		public virtual void ToggleBookMark()
		{
			this.ToggleBookMark(this.owner.Position.Y, int.MaxValue);
		}
		public virtual void ToggleBookMark(Point position, int group, int bookMark, int imageIndex, string name, string description, string url, object tag)
		{
			if (this.shared)
			{
				BookMarkManager.SharedBookMarks.ToggleBookMark(position, group, bookMark, imageIndex, name, description, url, tag, this.owner.FileName);
			}
			else
			{
				int num = this.InternalFind(bookMark, position.Y, group);
				if (num >= 0)
				{
					this.ClearBookMarkByIndex(num);
				}
				else
				{
					this.SetBookMark(position, group, bookMark, imageIndex, name, description, url, tag);
				}
			}
		}
		public virtual void ToggleBookMark(int line, int group, int bookMark, int imageIndex)
		{
			this.ToggleBookMark(new Point(0, line), group, bookMark, imageIndex, string.Empty, string.Empty, string.Empty, null);
		}
		public virtual void ToggleBookMark(Point position, int group, int bookMark, int imageIndex)
		{
			this.ToggleBookMark(position, group, bookMark, imageIndex, string.Empty, string.Empty, string.Empty, null);
		}
		public virtual void ToggleBookMark(Point position, int group, int bookMark, int imageIndex, string name, string description, string url)
		{
			this.ToggleBookMark(position, group, bookMark, imageIndex, name, description, url, null);
		}
		public virtual void ToggleBookMark(int group, int bookMark, int imageIndex)
		{
			this.ToggleBookMark(this.owner.Position, group, bookMark, imageIndex);
		}
		public virtual void ClearBookMark(int bookMark)
		{
			if (!this.shared)
			{
				int num = this.FindByIndex(bookMark);
				if (num >= 0)
				{
					this.ClearBookMarkByIndex(num);
				}
			}
		}
		public virtual void ClearBookMark(int line, int bookmark)
		{
			this.ClearBookMark(line, -1, bookmark);
		}
		public virtual void ClearBookMarkByIndex(int index)
		{
			if (index >= 0)
			{
				this.owner.BeginUpdate(UpdateReason.Other);
				try
				{
					int line = base[index].Line;
					base.RemoveAt(index);
					this.owner.State |= NotifyState.BookMarkChanged;
					this.owner.LinesChanged(line, line);
				}
				finally
				{
					this.owner.EndUpdate();
				}
			}
		}
		public new virtual void Clear()
		{
			if (this.shared)
			{
				BookMarkManager.SharedBookMarks.Clear(this.owner.FileName);
			}
			else
			{
				if (base.Count > 0)
				{
					this.owner.BeginUpdate(UpdateReason.Other);
					try
					{
						base.Clear();
						this.owner.LinesChanged(0, int.MaxValue);
						this.owner.State |= NotifyState.BookMarkChanged;
					}
					finally
					{
						this.owner.EndUpdate();
					}
				}
				else
				{
					base.Clear();
				}
			}
		}
		public virtual void ClearBookMarks(int line)
		{
			this.ClearBookMarks(line, -1);
		}
		public virtual void ClearBookMarks(int line, int group)
		{
			if (this.shared)
			{
				BookMarkManager.SharedBookMarks.ClearBookMarks(line, group, this.owner.FileName);
			}
			else
			{
				int num = 0;
				bool flag = false;
				if (base.FindLast(new BookMark(line), out num, this.lineComparer))
				{
					this.owner.BeginUpdate(UpdateReason.Other);
					try
					{
						for (int i = num; i >= 0; i--)
						{
							if (base[i].Line != line)
							{
								break;
							}
							if (base[i].Group == group || group == -1)
							{
								base.RemoveAt(i);
								flag = true;
							}
						}
						if (flag)
						{
							this.owner.State |= NotifyState.BookMarkChanged;
							this.owner.LinesChanged(line, line);
						}
					}
					finally
					{
						this.owner.EndUpdate();
					}
				}
			}
		}
		public virtual void ClearBookMark(int line, int group, int bookMark)
		{
			if (this.shared)
			{
				BookMarkManager.SharedBookMarks.ClearBookMark(line, group, bookMark, this.owner.FileName);
			}
			else
			{
				int num = this.InternalFind(bookMark, line, group);
				if (num >= 0)
				{
					this.ClearBookMarkByIndex(num);
				}
			}
		}
		public virtual void ClearBookMarksByGroup(int group)
		{
			if (this.shared)
			{
				BookMarkManager.SharedBookMarks.Clear(group, this.owner.FileName);
			}
			else
			{
				this.owner.BeginUpdate(UpdateReason.Other);
				try
				{
					for (int i = base.Count - 1; i >= 0; i--)
					{
						if (base[i].Group == group || group == -1)
						{
							base.RemoveAt(i);
						}
					}
					this.owner.State |= NotifyState.BookMarkChanged;
					this.owner.LinesChanged(0, int.MaxValue);
				}
				finally
				{
					this.owner.EndUpdate();
				}
			}
		}
		public virtual void ClearBookMarks()
		{
			this.Clear();
		}
		public virtual void ClearUnnumberedBookMarks()
		{
			if (this.shared)
			{
				BookMarkManager.SharedBookMarks.ClearUnnumberedBookMarks(this.owner.FileName);
			}
			else
			{
				bool flag = false;
				this.owner.BeginUpdate(UpdateReason.Other);
				try
				{
					for (int i = base.Count - 1; i >= 0; i--)
					{
						if (base[i].Index == int.MaxValue)
						{
							base.RemoveAt(i);
							flag = true;
						}
					}
					if (flag)
					{
						this.owner.State |= NotifyState.BookMarkChanged;
						this.owner.LinesChanged(0, int.MaxValue);
					}
				}
				finally
				{
					this.owner.EndUpdate();
				}
			}
		}
		public virtual void ClearAllBookMarks()
		{
			this.ClearBookMarks();
		}
		public virtual void ClearAllUnnumberedBookmarks()
		{
			this.ClearUnnumberedBookMarks();
		}
		public virtual int NextBookMark()
		{
			return this.NextBookMark(-1);
		}
		public virtual int NextBookMark(int group)
		{
			int result;
			if (this.shared)
			{
				result = BookMarkManager.SharedBookMarks.NextBookMark(group, this.owner.FileName);
			}
			else
			{
				int num = -1;
				using (List<IBookMark>.Enumerator enumerator = base.GetEnumerator())
				{
					while (enumerator.MoveNext())
					{
						BookMark bookMark = (BookMark)enumerator.Current;
						if (bookMark.Index > num && (bookMark.Group == group || group == -1))
						{
							num = bookMark.Index;
						}
					}
				}
				result = num + 1;
			}
			return result;
		}
		public virtual void GotoBookMark(int bookMark)
		{
			if (!this.shared)
			{
				int num = this.FindByIndex(bookMark);
				if (num >= 0)
				{
					IBookMark bookMark2 = base[num];
					this.owner.BeginUpdate(UpdateReason.Navigate);
					try
					{
						this.owner.State |= (NotifyState.GotoBookMark | NotifyState.CenterLine);
						this.owner.MoveTo(bookMark2.Pos, bookMark2.Line);
					}
					finally
					{
						this.owner.EndUpdate();
					}
				}
			}
		}
		public virtual void GotoNextBookMark()
		{
			if (this.shared)
			{
				BookMarkManager.SharedBookMarks.GotoNextBookMark();
			}
			else
			{
				this.GotoBookMarkIndex(true);
			}
		}
		public virtual void GotoNextBookMark(int group)
		{
			if (this.shared)
			{
				BookMarkManager.SharedBookMarks.GotoNextBookMark(group);
			}
			else
			{
				this.GotoBookMarkIndex(true, group);
			}
		}
		public virtual void GotoPrevBookMark()
		{
			if (this.shared)
			{
				BookMarkManager.SharedBookMarks.GotoPrevBookMark();
			}
			else
			{
				this.GotoBookMarkIndex(false);
			}
		}
		public virtual void GotoPrevBookMark(int group)
		{
			if (this.shared)
			{
				BookMarkManager.SharedBookMarks.GotoPrevBookMark(group);
			}
			else
			{
				this.GotoBookMarkIndex(false, group);
			}
		}
		public virtual bool BlockDeleting(Rectangle rect)
		{
			bool result;
			if (this.shared)
			{
				result = BookMarkManager.SharedBookMarks.BlockDeleting(rect, this.owner.FileName);
			}
			else
			{
				bool flag = false;
				int num;
				base.FindLast(new BookMark(rect.Bottom), out num, this.lineComparer);
				if (num >= 0)
				{
					for (int i = Math.Min(num, base.Count - 1); i >= 0; i--)
					{
						IBookMark bookMark = base[i];
						if (bookMark.Line < rect.Top)
						{
							break;
						}
						if (this.ShouldDelete(bookMark, rect))
						{
							flag = true;
							base.RemoveAt(i);
						}
					}
				}
				result = flag;
			}
			return result;
		}
		public virtual bool PositionChanged(int x, int y, int deltaX, int deltaY)
		{
			return this.PositionChanged(x, y, deltaX, deltaY, this.lineComparer, this.bookMarkComparer);
		}
		public virtual void OnClick(IBookMark bookMark)
		{
			if (this.shared)
			{
				BookMarkManager.SharedBookMarks.OnClick(bookMark);
			}
			else
			{
				if (this.Click != null)
				{
					this.Click(this, new BookmarkClickEventArgs(bookMark));
				}
			}
		}
		public virtual void OnDoubleClick(IBookMark bookMark)
		{
			if (this.shared)
			{
				BookMarkManager.SharedBookMarks.OnDoubleClick(bookMark);
			}
			else
			{
				if (this.DoubleClick != null)
				{
					this.DoubleClick(this, new BookmarkClickEventArgs(bookMark));
				}
			}
		}
		public virtual bool OnShowTooltip(ref string tooltip, IBookMark bookMark)
		{
			bool result;
			if (this.shared)
			{
				result = BookMarkManager.SharedBookMarks.OnShowTooltip(ref tooltip, bookMark);
			}
			else
			{
				if (this.ShowToolTip != null)
				{
					ToolTipEventArgs toolTipEventArgs = new ToolTipEventArgs(tooltip, bookMark);
					this.ShowToolTip(this, toolTipEventArgs);
					tooltip = toolTipEventArgs.Tooltip;
					result = toolTipEventArgs.Handled;
				}
				else
				{
					result = false;
				}
			}
			return result;
		}
		public virtual ImageList GetImages(int group)
		{
			return this.shared ? BookMarkManager.SharedBookMarks.GetImages(group) : null;
		}
	}
}
